package com.cloudbroker.bcs.platform.ltb.common.ext.filter;

import com.cloudbroker.bcs.platform.ltb.common.ext.support.XssHttpServletRequestWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by xuyn15828 on 2016/3/26.
 */
public class XSSFilter implements Filter {
    private static final Logger logger = LoggerFactory.getLogger(XSSFilter.class);
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        String reqUri = request.getRequestURI();
        long startTime = System.currentTimeMillis();
        chain.doFilter(new XssHttpServletRequestWrapper(request), response);
        long endTime = System.currentTimeMillis();
        logger.error("request output =======> " + reqUri + " spend time : " + (endTime-startTime) + " millis");
    }

    @Override
    public void destroy() {

    }
}
